package com.leetcode.partition8;

import java.io.*;
import java.util.Arrays;

/**
 * @author rkc
 * @date 2022/8/15 9:07
 */
public class LC768最多能完成排序的块II {

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int n = nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) arr[i] = nextInt();
        writer.println(maxChunksToSorted(arr));
        writer.flush();
    }

    public static int maxChunksToSorted(int[] arr) {
        int[] temp = new int[arr.length];
        System.arraycopy(arr, 0, temp, 0, arr.length);
        Arrays.sort(temp);
        int ans = 0;
        long s1 = 0, s2 = 0;
        for (int i = 0; i < arr.length; i++) {
            s1 += arr[i];
            s2 += temp[i];
            if (s1 == s2) ans++;
        }
        return ans;
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
